package cn.xtcode.domain.activity.service.trial.thread;

import cn.xtcode.domain.activity.adapter.repository.IActivityRepository;
import cn.xtcode.domain.activity.model.valobj.GroupBuyActivityDiscountVO;
import cn.xtcode.domain.activity.model.valobj.SCSkuActivityVO;
import cn.xtcode.types.enums.ResponseCode;
import cn.xtcode.types.exception.AppException;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;

/**
 * @Author xt-code
 * @Description:
 * @Create 2025/5/6 16:53
 */
@Slf4j
public class QueryGroupBuyActivityDiscountVOThreadTask implements Callable<GroupBuyActivityDiscountVO> {
    /**
     * 来源
     */
    private final String source;

    /**
     * 渠道
     */
    private final String channel;


    private final String goodsId;
    /**
     * 活动仓储
     */
    private final IActivityRepository activityRepository;

    public QueryGroupBuyActivityDiscountVOThreadTask(String source, String channel, String goodsId, IActivityRepository activityRepository) {
        this.source = source;
        this.channel = channel;
        this.goodsId = goodsId;
        this.activityRepository = activityRepository;
    }

    @Override
    public GroupBuyActivityDiscountVO call() throws Exception {
        // 查询渠道商品活动配置关联配置
        SCSkuActivityVO scSkuActivityVO = activityRepository.querySCSkuActivityBySCGoodsId(source, channel, goodsId);
        if (null == scSkuActivityVO) {
            log.info("不存在source:{},channel:{},goodsId:{} 的商品", source, channel, goodsId);
            throw new AppException(ResponseCode.DATA_NOT_EXIST);
        }

        //根据activityId查找活动
        return activityRepository.queryGroupBuyActivityDiscountVO(scSkuActivityVO.getActivityId());
    }
}
